<template>
	<view class="container">
		<view class="add" v-if="!card" @click="addCard">
			<text>+ 添加银行卡</text>
		</view>
		<view class="" v-if="card">
			<view class="card">
				<view class="name">
					{{bank_name}}
				</view>
				<view class="number">
					{{bank_card}}
				</view>
			</view>
			
			<view class="btn">
				<button class="btn1" type="default" @click="edit">编辑</button>
			</view>
			
			<view class="btn">
				<button class="btn2" type="default" @click="exit">删除</button>
			</view>
		</view>
		


	</view>
</template>

<script>
	import {
		bankDetail,
		delBank
	} from '../../../api/api.js'
	export default {
		data() {
			return {
				card: false,
				bank_name: '',
				bank_card: ''
			}
		},
		onLoad() {
			// this.getBankInfo()
		},
		onShow() {
			this.getBankInfo()
		},
		methods: {
			getBankInfo() {
				bankDetail().then(res => {
					console.log(res)
					if (res.data) {
						this.card = true
						this.bank_name = res.data.bank
						this.bank_card = res.data.bank_card
					} else {
						this.card = false
					}
				})
			},
			addCard(){
				uni.navigateTo({
					url:'/pages/agent/user/cardInfo'
				})
			},
			edit() {
				uni.navigateTo({
					url:'/pages/agent/user/cardInfo'
				})
			},
			exit() {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定解绑该卡么？',
					success: function(res) {
						if (res.confirm) {
							delBank().then(res=>{
								if(res.code == 1){
									uni.showModal({
										title: '提示',
										content: '银行卡解绑成功',
										showCancel: false,
										success() {
											that.getBankInfo()
										}
									})
								}
							})
						} else if (res.cancel) {
						}
					}
				})
			}
		},
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		height: calc(100% - 30upx);
		padding-top: 30upx;
		background-color: #f6f6f6;
	}

	.add {
		width: calc(100% - 60upx);
		height: 200upx;
		border-radius: 15upx;
		margin: 0 auto;
		border: 2upx dashed #3EB9FF;
		color: #3EB9FF;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.card {
		width: calc(100% - 60upx);
		height: 200upx;
		margin: 0 auto;
		background-image: url('../../../static/img/agent/card_bgc.png');
		background-size: 100%;
		display: flex;
		flex-direction: column;

		view {
			color: #FFFFFF;
			font-size: 32upx;
		}

		.name {
			margin: 30upx;
		}

		.number {
			margin-left: 30upx;
		}

	}

	.btn {
		width: calc(100% - 60upx);
		margin: 40upx auto;
		height: 90upx;
		border-radius: 45upx;
		overflow: hidden;

		button {
			width: 100%;
			height: 100%;
		}

		.btn1 {
			background-color: #3eb9fe;
			color: #FFFFFF;
		}

		.btn2 {
			color: #666666;
			height: 90upx;
			border-radius: 45upx;
			border: 1upx solid #A8A8A8;
		}


	}
</style>
